import Vue from 'vue'
export default async function (user, password) {
  let asyncResult = {//登录
    url: null,
    userName: null,
    userId: null,
    userCode: null,
    orgId: 0,
    ticket: null
  };
  await new Promise(function (resolve, reject) {
    console.log('wc',window.cordova)
    if (window.cordova) {
      Vue.prototype.$hybridApi.configHeader({
        show: false
      }); //配置去掉v平台的首页
      Vue.prototype.$hybridApi.getUserInfo({
        success: obj => {
          console.log("V平台接口成功",obj)
          let {
            requestUrl,
            loginName,
            userId,
            userCode,
            groupId,
            Ticket
          } = obj;
          asyncResult = {
            url: "http://"+requestUrl+"/Server.svc/api/invoke",
            userName: loginName,
            userId: userId,
            userCode:userCode,
            orgId: groupId,
            ticket: Ticket
          };
          resolve(asyncResult)
        }
      });
    } else {
      let requireObj = {
        "ApiType": "AppSecurtiyController",
        "Parameters": [{
            "Value": user
          },
          {
            "Value": password
          }
        ],
        "Method": "Login",
        "Context": {}
      }
      Vue.axios.post('/api/invoke', requireObj).then(res => {
        console.log("登录成功1res", res)
        let resObj = res.data;
        if (resObj.Success) {
          let orgId = resObj.Context.InvOrgId;
          let ticket = resObj.Context.Ticket;
          let userId = resObj.Result.UserId;
          let userName = resObj.Result.UserName;
          let userCode = resObj.Result.UserCode;
          asyncResult = {
            url: "/api/invoke",
            userName,
            userCode,
            userId,
            orgId,
            ticket
          };
          resolve(asyncResult)
        }
      })
    }
  })
  return asyncResult

}
